<?php

namespace app\admin\controller;

use basic\BaseController;
use services\JsonService;

/**
 * @title 系统控制类
 * Class SystemBasic
 * @package app\admin\controller
 */
class SystemBasic extends BaseController
{
    /**
     * @title 操作失败说明
     * @param string $msg 提示信息
     * @param string $backUrl 跳转地址
     * @param string $info 说明
     * @param int $duration 持续时间
     */
    protected function failedNotice($msg = "操作失败", $backUrl = "", $info = "", $duration = 3)
    {
        $type = "error";
        $this->assign(compact("msg", "backUrl", "info", "duration"));
        return $this->fetch("public/notice");
    }

    /**
     * @title 失败提示一直持续
     * @param string $msg
     * @param int $backUrl
     * @param string $info
     * @return string
     */
    protected function failedNoticeLast($msg = "操作失败", $backUrl = 0, $info = '')
    {
        return $this->failedNotice($msg, $backUrl, $info, 0);
    }

    /**
     * 操作成功提示框
     * @param string $msg 提示信息
     * @param int $backUrl 跳转地址
     * @param int $info
     * @param int $duration 持续时间
     * @return string
     */
    protected function successfulNotice($msg = "操作成功", $backUrl = 0, $info = 0, $duration = 3)
    {
        $type = "success";
        $this->assign(compact("msg", "backUrl", "info", "duration", "type"));
        return $this->fetch("public/notice");
    }

    /**
     * @title 错误提醒页面
     * @param string $msg
     * @param int $url
     */
    protected function failed($msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
    {
        if ($this->request->isAjax()) {
            exit(JsonService::fail($msg, $url)->getContent());
        } else {
            $this->assign(compact("msg", "url"));
            exit($this->fetch("public/error"));
        }
    }

    /**
     * @title 成功的提示页面
     * @param $msg
     * @param int $url
     */
    protected function successful($msg, $url = 0)
    {
        if ($this->request->isAjax()) {
            exit(JsonService::successful($msg, $url)->getContent());
        } else {
            $this->assign(compact("msg", "url"));
            exit($this->fetch("public/success"));
        }
    }

    /**
     *异常抛出
     * @param string $msg
     */
    protected function exception($msg = "无法正常打开页面")
    {
        $this->assign(compact("msg"));
        exit($this->fetch("public/exception"));
    }

    /**
     * @tilte 找不到页面
     */
    protected function _empty()
    {
        exit($this->fetch("public/404"));
    }
}